<?php
	class Diaper{
		var $timestamp; //date in format YYYY-MM-DD hh24:mi:ss
		var $type = 0;
		
		public function setTime($time){
			//create new date time
			$date = new DateTime();
			
			//parse the time
			$timePattern = "/^([0-1][0-9]|2[0-3]):([0-5][0-9])$/";  //24-hr : seconds
			preg_match($timePattern, $time, $matches);
			if(sizeof($matches) == 3){
				$hrs = $matches[1];
				$sec = $matches[2];
							
				$date->setTime($hrs,$sec,0);
				//echo "from parse: " . $date->getTimestamp();
			}
			else {
				//echo "couldn't parse, use default: " . $date->getTimestamp();
				
			}
			$this->timestamp = $date;
			
			
		}
		
		public function getDateTime() {
			return $this->timestamp->format('Y-m-d H:i:s');
		}
		
		public function getTime() {
			return $this->timestamp->format('H:i');
		}
		
		public function toXml() {
			return "<diaper timestamp=\"".$this->getTime()."\" type=\"".$this->type."\"/>";
		}
	}

?>